<?php

//微信支付入口文件

    //加载微信配置
    // $WxSetting = $this->Payment->GetpaymentSettingInfo(array('mode'=>'wxpay'));
    require_once "WxPay.php";
    $WxSetting = array(
        'APPID'     => 'wx16320d7479a5774c',
        'MCHID'     => '1289698501',
        'KEY'       => 'fyh40082851514008285151400828515',
        'OPENDID'       => $_SESSION['Member_info'][0]['openid'],
        'CertFile'      => './cert/',
        'notifyUrl'     => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],
    );
    $Body = 'scbkajbcjas';
    $trade_no = '45555523232323233';
    $money = 0.01;
    // print_r($WxSetting);exit;
    $WxPay = new WxPay($WxSetting);
	var_dump($_SESSION['Member_info']);

    //发起支付反馈参数
    $Result = $WxPay->SubmitJsApiUnifiedOrder($Body, $trade_no, $money);
	var_dump($Result);
    //返回网页前端发起参数
    $SignParam = $WxPay->signJsApiPrepayParam($Result['prepay_id']);
    // print_r($Result);exit;

 ?>
 
<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
	<title>支付</title>
	<link rel="stylesheet" href="css/core.css">
	<script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
	<script src="js/jquery.cookie.js" type="text/javascript"></script>
	<script src="js/layer/layer.js" type="text/javascript"></script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<section>
	<button class="zhifu-btn">立即支付</button>
</section>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">

$(function(){
	
	$(".zhifu-btn").click(function(){
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest',
			{
				"appId" : '<?php echo $SignParam['appId']; ?>',
				"timeStamp" : '<?php echo $SignParam['timeStamp']; ?>',
				"nonceStr" : '<?php echo $SignParam['nonceStr']; ?>',
				"package" : '<?php echo $SignParam['package']; ?>',
				"signType" : '<?php echo $SignParam['signType']; ?>',
				"paySign" : '<?php echo $SignParam['paySign']; ?>',
			},
			function(ret){
				if(ret.err_msg == "get_brand_wcpay_request:cancel"){
					layer.open({content:"您已取消了此次支付",skin:'msg',time:3});
				}else if(ret.err_msg == "get_brand_wcpay_request:fail"){
					layer.open({content:"支付失败，请重新尝试",skin:'msg',time:3});
				}else if(ret.err_msg == "get_brand_wcpay_request:ok"){
					layer.open({content:"支付成功",skin:'msg',time:3});
					//location.href = '';//跳转支付成功页面
				}else{
					layer.open({content:"未知错误"+ret.err_msg,skin:'msg',time:3});
				}
			}
		);
	});
});

</script>
</body>
</html>